function dataTableWrapper(param){

	var $table = param.table;
	var $table_id = "#" + $table.attr("id");
	var $add_btn = param.add_btn;
	var $add_row_before_func = param.add_row_before_func;
	var $add_row_after_func = param.add_row_after_func;
	var $add_row_data = param.add_row_data;
	var $del_btn = param.del_btn;
	
	var dragged;
    var startdrag = function( event, ui ) {
        dragged = $(event.target).closest('tr');
        dragged.addClass('dragged');
    };
    var stopdrag = function( event, ui ) {
        dragged.removeClass('dragged');
    };
    var dragging = function( event, ui ) {
        $($table_id +" tbody tr").each(function () {
            var lefttop = $(this).offset();
            var top = lefttop.top;
            var bottom = lefttop.top + $(this).height();
            var center = (top + bottom) / 2;
            
            if (this !== ui.helper[0]
                && event.pageY >= top
                && event.pageY <= bottom) {
                if (event.pageY > center) {
                    $(this).after(dragged);
                } else {
                    $(this).before(dragged);
                }
            }
        });
    }
	var dt = $table.DataTable( {
        //data:           data,
		searching: false,
		info:     false,
		ordering: false,
		paging:   false,
		scrollX:  false,
        scrollY:        200,
        scrollCollapse: true,
        drawCallback: function ( settings ) {
            $($table_id+' tbody tr').draggable({
                addClasses: false,
                drag: dragging,
                start: startdrag,
                stop: stopdrag
            });
        }
    } ); 
	$($table_id +' tbody').on( 'click', 'tr', function () {
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            dt.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
    } );
	$add_btn.on( 'click', function () {
		if(typeof $add_row_before_func == "function"){
			$add_row_data = $add_row_before_func();
		}
		
         dt.row.add( $add_row_data ).draw( false );
		 
		if(typeof $add_row_after_func == "function"){
			$add_row_after_func();
		}

        for (var i=0; i<$('#videos_table .short-input').length; i++)
        {
            $("#videos_table .short-input").eq(i).val(i+1);
        }

		return false;
     } );
	 if($del_btn){
		 $del_btn.on( 'click', function () {
			dt.row('.selected').remove().draw( false );
			return false;
		 } );
	 }
	return dt;
}

function getMaxTrCount(selector){

    

 var $max = -1;
 $(selector).each(function(){
	var count = parseInt(this.getAttribute("count"));
	$max = Math.max($max,count);
 });
 
 return $max;
}